<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	template="/templates/template.xhtml">

	<f:metadata>
		<f:event type="preRenderView" listener="#{proprietarioBean.verificarAcesso}" />
	</f:metadata>

	<ui:define name="body">
		<h:form id="form" prependId="false">
			<p:fieldset legend="#{proprietarioBean.qualifiedName}" id="fieldPrincipal">
				<h:panelGrid columns="2" id="panelCadastro" border="1" columnClasses="coluna15,coluna85" width="100%">
					<h:outputLabel value="Nome:" styleClass="icoObrigatorio" />
					<p:inputText value="#{proprietarioBean.model.nome}" id="nome" size="50" maxlength="255" />

					<h:outputLabel value="CPF:" styleClass="icoObrigatorio" />
					<p:inputMask mask="9?99.999.999-99" value="#{proprietarioBean.model.cpf}" id="cpf" size="30" maxlength="11" />

					<h:outputLabel value="Tipo de Proprietário:" styleClass="icoObrigatorio" />
					<p:selectOneMenu id="idTpProprietario" effect="fade" style="width:300px;"
						value="#{proprietarioBean.idTipoProprietario}">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{proprietarioBean.listaTipoProprietario}" />
					</p:selectOneMenu>

					<h:outputText value="Data de Nascimento:" styleClass="icoObrigatorio" />
					<p:inputMask mask="99/99/9999" value="${proprietarioBean.model.dtnascimentoFormat}" id="dtNascimento" size="30"
						maxlength="10" />

					<h:outputLabel value="Endereço:" styleClass="icoObrigatorio" />
					<p:inputText value="#{proprietarioBean.model.lograudouro}" id="endereco" size="50" maxlength="255" />

					<h:outputLabel value="RG:" />
					<p:inputText value="#{proprietarioBean.model.rg}" id="rg" size="30" maxlength="50" />

					<h:outputText value="UF:" />
					<p:selectOneMenu id="uf" value="#{proprietarioBean.idUf}" effect="fade" style="width:300px;">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{proprietarioBean.ufs}" />
						<p:ajax update="municipio" process="@this" event="change" listener="#{proprietarioBean.changeUF}" />
					</p:selectOneMenu>

					<h:outputText value="Municipio:" />
					<p:selectOneMenu id="municipio" value="#{proprietarioBean.idMunicipio}" effect="fade" style="width:300px;">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{proprietarioBean.municipios}" />
					</p:selectOneMenu>

					<h:outputLabel value="Telefone Comercial:" />
					<p:inputMask mask="(99)9999-9999" value="#{proprietarioBean.model.telefoneComercial}" id="comercial" size="50" />

					<h:outputLabel value="Telefone Residencial:" />
					<p:inputMask mask="(99)9999-9999" value="#{proprietarioBean.model.telefoneResidencial}" id="residencial" size="50" />

					<h:outputLabel value="Telefone Celular:" />
					<p:inputMask mask="(99)9999-9999" value="#{proprietarioBean.model.telefoneCelular}" id="cel" size="50" />
				</h:panelGrid>
				<br />
				<p:toolbar>
					<p:toolbarGroup align="left">
						<p:commandButton value="Limpar" immediate="true" ajax="false" action="proprietario.jsf" />
						<p:commandButton rendered="#{p:ifGranted('ROLE_PROPRIETARIO_SALVAR')}" value="Salvar" ajax="true" process="@form"
							update="@form" action="#{proprietarioBean.save}" />
					</p:toolbarGroup>
				</p:toolbar>
				<br />
				<p:dataTable var="lista" id="listaRes" emptyMessage="#{proprietarioBean.emptyMessage}" update="listaRes"
					rowsPerPageTemplate="#{proprietarioBean.paginacao}" styleClass="coluna100"
					value="#{proprietarioBean.lazyDataModel}" paginator="true" rows="5"
					rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'linhaImpar' : 'linhaPar'}" rowIndexVar="rowIx">

					<p:column headerText="Nome" sortBy="#{lista.nome}" filterBy="#{lista.nome}" style="width:20%">
						<h:outputLabel value="#{lista.nome}" />
					</p:column>
					<p:column headerText="CPF" sortBy="#{lista.cpf}" filterBy="#{lista.cpf}" style="width:10%">
						<h:outputLabel value="#{lista.cpfFormat}" />
					</p:column>

					<p:column headerText="Tipo de Proprietário" sortBy="#{lista.tipoProprietario.descricao}"
						filterBy="#{lista.tipoProprietario.descricao}" style="width:25%">
						<h:outputLabel value="#{lista.tipoProprietario.descricao}" />
					</p:column>
					<p:column headerText="Endereço" sortBy="#{lista.lograudouro}" filterBy="#{lista.lograudouro}" style="width:20%">
						<h:outputLabel value="#{lista.lograudouro}" />
					</p:column>
					<p:column headerText="Celular" sortBy="#{lista.telefoneCelular}" filterBy="#{lista.telefoneCelular}"
						style="width:15%">
						<h:outputLabel value="#{lista.telefoneCelularFormat}" />
					</p:column>

					<p:column style="width:10%;text-align:center;">
						<f:facet name="header">
							<h:outputLabel value="Ações" />
						</f:facet>
						<p:commandLink rendered="#{p:ifGranted('ROLE_PROPRIETARIO_EDITAR')}" title="Editar"
							style="padding:5px !important;" update=":form:panelCadastro" process="@this" action="#{proprietarioBean.load}">
							<h:graphicImage library="design/imagem" name="icone-editar.png" />
							<f:setPropertyActionListener target="#{proprietarioBean.model}" value="#{lista}" />
						</p:commandLink>
						<p:commandLink rendered="#{p:ifGranted('ROLE_PROPRIETARIO_EXCLUIR')}" title="Excluir" process="@this"
							oncomplete="confirmation.show()">
							<h:graphicImage library="design/imagem" name="icone-excluir.png" />
							<f:setPropertyActionListener target="#{proprietarioBean.model}" value="#{lista}" />
						</p:commandLink>
					</p:column>
				</p:dataTable>
				<p:confirmDialog appendToBody="true" message="Confirma a Exclusão" header="Exclusão" severity="alert"
					widgetVar="confirmation">
					<h:panelGrid columns="2">
						<p:commandButton value="Sim" update=":form:listaRes" oncomplete="confirmation.hide()"
							actionListener="#{proprietarioBean.delete}" immediate="true" />
						<p:commandButton value="Não" onclick="confirmation.hide()" />
					</h:panelGrid>
				</p:confirmDialog>
			</p:fieldset>
		</h:form>
	</ui:define>
</ui:composition>